from flask import Blueprint, request

user_blueprint = Blueprint('user', __name__)
tokens = {
    'admin': {
        'token': 'admin-token'
    },
    'editor': {
        'token': 'editor-token'
    }
}
users = {
    'admin-token': {
        'roles': ['admin'],
        'introduction': 'I am a super administrator',
        'avatar': 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        'name': 'Super Admin'
    },
    'editor-token': {
        'roles': ['editor'],
        'introduction': 'I am an editor',
        'avatar': 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        'name': 'Normal Editor'
    }
}


@user_blueprint.post('/login')
def user_login():
    un = request.json['username']
    return {
        'code': 0,
        'data': tokens[un]
    }


@user_blueprint.get('/info')
def user_info():
    print(request.get_data())
    print(request.form)
    u = users[request.args['token']]
    return {
        'code': 0,
        'data': u
    }
